package work11;



import java.util.HashSet;
import java.util.Iterator;

/**
 * @author ybb
 * 去除集合中自定义对象的重复值(对象的成员变量值都相同)
 */
public class Task02 {
    public static void main(String[] args) {
// 创建学生对象
        HashSet<Student> studentHashSet=new HashSet<Student>();

        Student student1= new Student("林青霞",27);
        Student student2 = new Student("林志玲", 40);
        Student student3 = new Student("凤姐", 35);
        Student student4 = new Student("芙蓉姐姐", 18);
        Student student5 = new Student("翠花", 16);
        Student student6 = new Student("林青霞", 27);
        Student student7 = new Student("林青霞", 18);
// 集合对象中添加这些学生对象
        studentHashSet.add(student1);
        studentHashSet.add(student2);
        studentHashSet.add(student3);
        studentHashSet.add(student4);
        studentHashSet.add(student5);
        studentHashSet.add(student6);
        studentHashSet.add(student7);


// 去除集合中这些重复值（假设对象中的成员变量值都相同，则认为该这些对象是重复）
        Iterator iterator=studentHashSet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

    }
}
